load("@fbcode_macros//build_defs:export_files.bzl", "export_file")
load("@fbcode_macros//build_defs:native_rules.bzl", "buck_filegroup", "buck_genrule")
load("@fbsource//xplat/third-party/yarn:yarn_offline_mirror_helper.bzl", "yarn_offline_mirror_path")

oncall("build_infra")

buck_genrule(
    name = "html",
    srcs = [":files"],
    out = "output_format.html",
    cmd = '$(exe //buck2/app/buck2_explain/js:build_html_script) --yarn "$(exe fbsource//xplat/third-party/yarn:yarn)" --yarn-offline-mirror "{yarn_offline_mirror}" -o "$OUT" --src "$(location :files)" --tmp "$TMP"'.format(yarn_offline_mirror = yarn_offline_mirror_path(yarn_lock = "./yarn.lock")),
)

buck_filegroup(
    name = "files",
    srcs = glob(
        [
            "src/**",
            "*",
        ],
        exclude = [
            "node_modules/**",
            "dist/**",
        ],
    ) + [":schema_ts"],
)

buck_genrule(
    name = "schema_ts",
    srcs = [
        "output_format.fbs",
    ],
    out = "src/fbs",
    cmd = "$(exe fbsource//third-party/flatbuffers-23.5.26:flatc) --ts -o ${OUT} ${SRCS}",
    default_outs = ["."],
)

export_file(
    name = "output_format.fbs",
)
